<?php
namespace App\Manager;

use Overtrue\LaravelUEditor\StorageManager as OldStorageManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;

/**
 * Class StorageManager.
 */
class StorageManager extends OldStorageManager
{

    public function getUrl($filename)
    {
        if (method_exists($this->disk, 'url')) {
            return $this->disk->url($filename);
        }

        return $this->url($filename);
    }

    protected function getFilename(UploadedFile $file, array $config)
    {
        $md5 = md5_file($file->getRealPath());
        $ext = $file->getClientOriginalExtension();

        $path1 = substr($md5, 0, 3);
        $path2 = substr($md5, 3, 3);
        $filename = $md5.'.'.$ext;
        $foldpath = '/uploads/image/'.$path1.'/'.$path2.'/';

        return $foldpath . $filename;
    }

}
